<template>
  <div>
  <el-card class="box-card">
      <div slot="header" class="clearfix">
        <span>线索管理</span>
      </div>
      <el-form ref="form" :model="form" label-width="165px" :rules="rules">
        <el-form-item label="线索回收时限" prop="limitTime">
          <el-input-number v-model="form.limitTime" :precision="0" :min="1" :step="1" placeholder="请输入" controls-position="right" />
          <el-select v-model="form.limitTimeType" placeholder="请选择线索回收时限类型">
            <el-option
              v-for="dict in limitTimeTypeOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="dict.dictValue"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="线索回收到期提醒定时" prop="warnTime">
          <el-input-number v-model="form.warnTime" :precision="0" :min="1" :step="1" placeholder="请输入" controls-position="right" />
          <el-select v-model="form.warnTimeType" placeholder="请选择线索回收到期提醒定时类型">
            <el-option
              v-for="dict in warnTimeTypeOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="dict.dictValue"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="重复捞取时间限制" prop="repeatGetTime">
          <el-input-number v-model="form.repeatGetTime" :precision="0" :min="1" :step="1" placeholder="请输入" controls-position="right" />
          <el-select v-model="form.repeatType" placeholder="请选择重复捞取时间限制类型">
            <el-option
              v-for="dict in repeatGetTimeTypeOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="dict.dictValue"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="个人保有量限制" prop="maxNunmber">
          <el-input-number v-model="form.maxNunmber" :precision="0" :min="1" :max="99" :step="1" placeholder="请输入" controls-position="right" />
          <span class="unit">个</span>
        </el-form-item>
        <el-form-item class="search-btn">
          <el-button class="cus-search-btn" type="primary" @click="doSave">保存</el-button>
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>

<script>
export default {
  data () {
    return {
      form: {
        id: null,
        limitTime: null,
        limitTimeType: '0',
        warnTime: null,
        warnTimeType: '0',
        repeatGetTime: null,
        repeatType: '0',
        maxNunmber: null,
        type: 0
      },
      rules:{
        limitTime: [
          { required: true, message: '线索回收时限不能为空', trigger: 'blur' }
        ],
        warnTime:[
          { required: true, message: '线索回收到期提醒定时不能为空', trigger: 'blur'}
        ],
        repeatGetTime: [
          { required: true, message: '重复捞取时间限制不能为空', trigger: 'blur'}
        ],
        maxNunmber: [
          { required: true, message: '个人保有量限制不能为空', trigger: 'blur'}
        ]
      },
      limitTimeTypeOptions: [],
      warnTimeTypeOptions: [],
      repeatGetTimeTypeOptions: [],
    }
  },
  created () {
    this.getDicList()
    this.$nextTick(() => {
      this.$refs.form.resetFields()
      this.getInfo()
    })
  },
  methods: {
    // 获取信息
    getInfo () {
      this.$axios.get("/api/tb/rule/getInfo/"+this.form.type)
        .then((res) => {
          if (res.data.code == 200) {
            this.form = res.data.data;
          } else {
            this.$message.error(res.data.msg);
          }
        }).catch((err) => {
          console.log(err);
        });
    },
    getDicList () {
      this.$axios.get("/api/sys/dictData/optionselect/limit_time")
        .then((res) => {
          if (res.data.code == 200) {
            this.limitTimeTypeOptions = res.data.data;
          } else {
            this.$message.error(res.data.msg);
          }
        }).catch((err) => {
          console.log(err);
        });
      this.$axios.get("/api/sys/dictData/optionselect/warn_time")
        .then((res) => {
          if (res.data.code == 200) {
            this.warnTimeTypeOptions = res.data.data;
          } else {
            this.$message.error(res.data.msg);
          }
        }).catch((err) => {
          console.log(err);
        });
      this.$axios.get("/api/sys/dictData/optionselect/repeat_get_time")
        .then((res) => {
          if (res.data.code == 200) {
            this.repeatGetTimeTypeOptions = res.data.data;
          } else {
            this.$message.error(res.data.msg);
          }
        }).catch((err) => {
          console.log(err);
        });
    },
    doSave() {
      this.$refs["form"].validate((vali) => {
        if (vali) {
          //发送ajax请求
          this.$axios.post(this.form.id?"/api/tb/rule/update":"/api/tb/rule/save", this.form)
            .then((res) => {
              if (res.data.code == 200) {
                //1.友好提示
                this.$message.success(res.data.msg);
              } else {
                //1.友好提示
                this.$message.error(res.data.msg);
              }
            })
            .catch((err) => {
              console.log(err);
            });
        }
      });
    }
  }
}
</script>

<style  scoped>

</style>
